<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="solution" @click="showConditionModel()">筛选专家</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="tableData"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap"/>
    </div>


    <a-modal
      title="选择筛选条件"
      width="50%"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >

      <RandomSpecialistFilter ref="randomSpecialistFilter"/>
    </a-modal>
  </a-card>

</template>

<script>

  import { getRandomSpecialist } from '@/api/api'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import RandomSpecialistFilter from './modules/RandomSpecialistFilter'

  export default {
    name: "SpecialistList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      RandomSpecialistFilter
    },
    data () {
      return {
        tableData: [],
        description: '专家筛选页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'专家名称',
            align:"center",
            dataIndex: 'specialistName'
          },
          {
            title:'专家性别',
            align:"center",
            dataIndex: 'specialistSex_dictText'
          },
          {
            title:'职务',
            align:"center",
            dataIndex: 'job'
          },
          {
            title:'工作单位',
            align:"center",
            dataIndex: 'workUnit'
          },
          {
            title:'技术专长',
            align:"center",
            dataIndex: 'technicalExpertise_dictText'
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'specialistPhone'
          },
          {
            title:'专家类型',
            align:"center",
            dataIndex: 'specialistType_dictText'
          },{
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'更新时间',
            align:"center",
            dataIndex: 'updateTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          }
        ],
        url: {
          list: "/specialist/list",
          delete: "/specialist/delete",
          deleteBatch: "/specialist/deleteBatch",
          exportXlsUrl: "/specialist/exportXls",
          importExcelUrl: "/specialist/importExcel",
        },
        dictOptions:{},
        visible: false,
        confirmLoading: false
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      showConditionModel(){
        this.visible = true
      },
      handleOk(e) {
        let condition = this.$refs.randomSpecialistFilter.data;
        for(let i=0; i<condition.length; i++){
          if(condition[i].technicalExpertise === undefined || condition.technicalExpertise===''
            || condition[i].specialistType === undefined || condition.specialistType===''
            || condition[i].numberOfSpecialist === undefined || condition.numberOfSpecialist===''){
            alert("参数不能为空")
            break
          }

          for(let j=i+1; j<condition.length; j++){
            if(condition[i].technicalExpertise===condition[j].technicalExpertise
              && condition[i].specialistType === condition[j].specialistType){         //第一个等同于第二个，splice方法删除第二个
              condition.splice(j,1);
              j--;
            }
          }
        }
        this.visible = false;
        this.loading = true;
        getRandomSpecialist({"condition":JSON.stringify(condition)}).then((res) => {
          if (res.success) {
            this.tableData = res.result
          }
          this.loading = false;
        });
      },
      handleCancel(e) {
        this.visible = false;
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>